#!/usr/bin/env Rscript
##################################
############ Preamble ############
##################################
# set language to English
Sys.setenv(LANG = "en")

# clean up
rm(list = ls())

# Set working directory: Please set your own
if (Sys.getenv("RSTUDIO") == "1") setwd("~/Dropbox/cues_bjps_replication")

library(Rmisc)
library(tidyverse)
library(readxl)
library(stargazer)
library(kableExtra)
library(sandwich)
library(broom)
library(dotwhisker)
library(jtools)
library(scales)



# read data
raw_data <- read_xlsx("data/final_survey_data.xlsx")

# rename variables
raw_data <- raw_data %>%
  dplyr::rename(
    number = lfdn,
    completion_time = duration,
    disposition_code = dispcode,
    treatment = c_0031,
    cover_page = v_27,
    age = v_28,
    age_range = v_29,
    gender = v_30,
    state = v_31,
    born_in_germany = v_39,
    sign_petition_self = v_47,
    sensitive_item_agree = dupl1_v_44,
    left_right = dupl1_v_41,
    petition_appropriate_self = v_48,
    sign_petition_others = v_49,
    petition_appropriate_others = v_50,
    delete_tweet = v_51,
    voted_2021 = v_53,
    party_voted_2021 = v_54,
    party_voted_2021_other_which = v_55,
    voted_2017 = v_56,
    party_voted_2017 = v_57,
    party_voted_2017_other_which = v_58,
    household_income = v_59,
    education = v_60,
    mother_born_where = v_61,
    mother_born_other_where = v_62,
    father_born_where = v_63,
    father_born_other_where = v_64
  )

raw_data <- raw_data %>%
  mutate(treatment = replace(treatment, which(treatment == 1), "Mainstream Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 2), "Mainstream Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 3), "RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 4), "RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 5), "Mainstream and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 6), "Mainstream and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 7), "Mainstream Disapprove and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 8), "Mainstream Disapprove and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 9), "Control")) %>%
  mutate(treatment = replace(treatment, which(treatment == 10), "Control"))

# recode state names
raw_data <- raw_data %>%
  mutate(state = replace(state, which(state == 1), "Baden-Wuerttemberg")) %>%
  mutate(state = replace(state, which(state == 2), "Bayern")) %>%
  mutate(state = replace(state, which(state == 3), "Berlin")) %>%
  mutate(state = replace(state, which(state == 4), "Brandenburg")) %>%
  mutate(state = replace(state, which(state == 5), "Bremen")) %>%
  mutate(state = replace(state, which(state == 6), "Hamburg")) %>%
  mutate(state = replace(state, which(state == 7), "Hessen")) %>%
  mutate(state = replace(state, which(state == 8), "Mecklenburg-Vorpommern")) %>%
  mutate(state = replace(state, which(state == 9), "Niedersachsen")) %>%
  mutate(state = replace(state, which(state == 10), "Nordrhein-Westfalen")) %>%
  mutate(state = replace(state, which(state == 11), "Rheinland-Pfalz")) %>%
  mutate(state = replace(state, which(state == 12), "Saarland")) %>%
  mutate(state = replace(state, which(state == 13), "Sachsen")) %>%
  mutate(state = replace(state, which(state == 14), "Sachsen-Anhalt")) %>%
  mutate(state = replace(state, which(state == 15), "Schleswig-Holstein")) %>%
  mutate(state = replace(state, which(state == 16), "Thueringen"))

# recode age_ranges
raw_data <- raw_data %>%
  mutate(age_range = replace(age_range, which(age_range == 1), "18 - 29 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 2), "30 - 39 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 3), "40 - 49 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 4), "50 - 59 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 5), "60 - 90 years"))

# recode income
raw_data <- raw_data %>%
  mutate(household_income = replace(household_income, which(household_income == 1), "Live comfortable")) %>%
  mutate(household_income = replace(household_income, which(household_income == 2), "Make ends meet")) %>%
  mutate(household_income = replace(household_income, which(household_income == 3), "Struggling")) %>%
  mutate(household_income = replace(household_income, which(household_income == 4), "Great difficulty")) %>%
  mutate(household_income = replace(household_income, which(household_income == 5), "Don't know"))


# recode gender
raw_data <- raw_data %>%
  mutate(gender = replace(gender, which(gender == 1), "Male")) %>%
  mutate(gender = replace(gender, which(gender == 2), "Female"))

# recode sensitive item - change sensitive item response "disagree" to 0
raw_data <- raw_data %>%
  mutate(sensitive_item_agree = replace(sensitive_item_agree, which(sensitive_item_agree == 2), 0))

# recode coordination game - change "not willing to sign" from 2 to 0
raw_data <- raw_data %>%
  mutate(sign_petition_self = replace(sign_petition_self, which(sign_petition_self == 2), 0))

# recode punishment exp - change "do not delete tweet" from 2 to 0
raw_data <- raw_data %>%
  mutate(delete_tweet = replace(delete_tweet, which(delete_tweet == 2), 0))

# recode left_right 100 is 0, 99 is NA
raw_data <- raw_data %>%
  mutate(left_right = replace(left_right, which(left_right == 100), 0)) %>%
  mutate(left_right = replace(left_right, which(left_right == 99), NA))

raw_data <- raw_data %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 1), "CDU/CSU")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 2), "SPD")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 3), "AfD")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 4), "Green")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 5), "FDP")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 6), "Die Linke"))

# remove incompletes or inattentives
analysis_data <- raw_data %>%
  filter(disposition_code == "31" | disposition_code == "32")

# clean up sensitive item - drop -77s, merge both columns
analysis_data <- analysis_data %>%
  mutate(sensitive_item_agree = replace(sensitive_item_agree, which(sensitive_item_agree < 0), NA))

# Create dummy variable
analysis_data$MRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream Approve", 1, 0)
analysis_data$RRPapprovedummy <- ifelse(analysis_data$treatment == "RRP Approve", 1, 0)
analysis_data$MRPapproveRRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream and RRP Approve", 1, 0)
analysis_data$MRPdisapproveRRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream Disapprove and RRP Approve", 1, 0)


# cleaning - Struggling and Great Difficulty

# subset analysis data
analysis_data_strugglingandgreatdifficulty <- analysis_data %>%
  filter(household_income == "Struggling" | household_income == "Great difficulty")

# mainstream only
mainstream_only_strugglingandgreatdifficulty <- analysis_data_strugglingandgreatdifficulty %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_strugglingandgreatdifficulty <- analysis_data_strugglingandgreatdifficulty %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_strugglingandgreatdifficulty <- analysis_data_strugglingandgreatdifficulty %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_strugglingandgreatdifficulty <- analysis_data_strugglingandgreatdifficulty %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_strugglingandgreatdifficulty[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_strugglingandgreatdifficulty[, c(18, 19, 20, 21, 22, 23)])
left_only_strugglingandgreatdifficulty[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_strugglingandgreatdifficulty[, c(18, 19, 20, 21, 22, 23)])
right_only_strugglingandgreatdifficulty[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_strugglingandgreatdifficulty[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_strugglingandgreatdifficulty[,c(18,19,20,21,22,23)]<-scale(rrp_only_strugglingandgreatdifficulty[,c(18,19,20,21,22,23)])



# Sensitive Item - Struggling and Great Difficulty

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_strugglingandgreatdifficulty <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_strugglingandgreatdifficulty)
sensitive_item_controls_leftonly_strugglingandgreatdifficulty <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_strugglingandgreatdifficulty)
sensitive_item_controls_rightonly_strugglingandgreatdifficulty <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_strugglingandgreatdifficulty)
# sensitive_item_controls_rrponly_strugglingandgreatdifficulty <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_strugglingandgreatdifficulty)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_strugglingandgreatdifficulty <- summ(sensitive_item_controls_fullsample_strugglingandgreatdifficulty, robust = "HC1")
robust_sensitive_item_controls_leftonly_strugglingandgreatdifficulty <- summ(sensitive_item_controls_leftonly_strugglingandgreatdifficulty, robust = "HC1")
robust_sensitive_item_controls_rightonly_strugglingandgreatdifficulty <- summ(sensitive_item_controls_rightonly_strugglingandgreatdifficulty, robust = "HC1")
# robust_sensitive_item_controls_rrponly_strugglingandgreatdifficulty <- summ(sensitive_item_controls_rrponly_strugglingandgreatdifficulty, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_strugglingandgreatdifficulty_df <- broom::tidy(robust_sensitive_item_controls_fullsample_strugglingandgreatdifficulty) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_strugglingandgreatdifficulty_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sensitive_item_controls_leftonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_strugglingandgreatdifficulty_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sensitive_item_controls_rightonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_strugglingandgreatdifficulty_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sensitive_item_controls_rrponly_strugglingandgreatdifficulty) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_strugglingandgreatdifficulty_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_strugglingandgreatdifficulty_df)[7] <- "term"


# Willingness to Sign Petition - Struggling and Great Difficulty


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_strugglingandgreatdifficulty <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_strugglingandgreatdifficulty)
sign_petition_self_controls_leftonly_strugglingandgreatdifficulty <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_strugglingandgreatdifficulty)
sign_petition_self_controls_rightonly_strugglingandgreatdifficulty <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_strugglingandgreatdifficulty)
# sign_petition_self_controls_rrponly_strugglingandgreatdifficulty <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_strugglingandgreatdifficulty)

# robust SEs
robust_sign_petition_self_controls_fullsample_strugglingandgreatdifficulty <- summ(sign_petition_self_controls_fullsample_strugglingandgreatdifficulty, robust = "HC1")
robust_sign_petition_self_controls_leftonly_strugglingandgreatdifficulty <- summ(sign_petition_self_controls_leftonly_strugglingandgreatdifficulty, robust = "HC1")
robust_sign_petition_self_controls_rightonly_strugglingandgreatdifficulty <- summ(sign_petition_self_controls_rightonly_strugglingandgreatdifficulty, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_strugglingandgreatdifficulty <- summ(sign_petition_self_controls_rrponly_strugglingandgreatdifficulty, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_strugglingandgreatdifficulty) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_strugglingandgreatdifficulty_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_strugglingandgreatdifficulty_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_strugglingandgreatdifficulty_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_strugglingandgreatdifficulty) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_strugglingandgreatdifficulty_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_strugglingandgreatdifficulty_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - Struggling and Great Difficulty

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_strugglingandgreatdifficulty)
petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_strugglingandgreatdifficulty)
petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_strugglingandgreatdifficulty)
# petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_strugglingandgreatdifficulty)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty <- summ(petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty <- summ(petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty <- summ(petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty <- summ(petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty_df)[7] <- "term"



# Empirical Expectations - Struggling and Great Difficulty

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_strugglingandgreatdifficulty <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_strugglingandgreatdifficulty)
sign_petition_others_controls_leftonly_strugglingandgreatdifficulty <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_strugglingandgreatdifficulty)
sign_petition_others_controls_rightonly_strugglingandgreatdifficulty <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_strugglingandgreatdifficulty)
# sign_petition_others_controls_rrponly_strugglingandgreatdifficulty <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_strugglingandgreatdifficulty)

# robust SEs
robust_sign_petition_others_controls_fullsample_strugglingandgreatdifficulty <- summ(sign_petition_others_controls_fullsample_strugglingandgreatdifficulty, robust = "HC1")
robust_sign_petition_others_controls_leftonly_strugglingandgreatdifficulty <- summ(sign_petition_others_controls_leftonly_strugglingandgreatdifficulty, robust = "HC1")
robust_sign_petition_others_controls_rightonly_strugglingandgreatdifficulty <- summ(sign_petition_others_controls_rightonly_strugglingandgreatdifficulty, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_strugglingandgreatdifficulty <- summ(sign_petition_others_controls_rrponly_strugglingandgreatdifficulty, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_strugglingandgreatdifficulty) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_strugglingandgreatdifficulty_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_strugglingandgreatdifficulty_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_strugglingandgreatdifficulty_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_strugglingandgreatdifficulty_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_strugglingandgreatdifficulty) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_strugglingandgreatdifficulty_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_strugglingandgreatdifficulty_df)[7] <- "term"



# Normative Expectations - Struggling and Great Difficulty

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_strugglingandgreatdifficulty)
petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_strugglingandgreatdifficulty)
petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_strugglingandgreatdifficulty)
# petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_strugglingandgreatdifficulty)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty <- summ(petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty <- summ(petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty <- summ(petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty <- summ(petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty_df)[7] <- "term"



# Sanctioning - Struggling and Great Difficulty

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_strugglingandgreatdifficulty <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_strugglingandgreatdifficulty)
delete_tweet_controls_leftonly_strugglingandgreatdifficulty <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_strugglingandgreatdifficulty)
delete_tweet_controls_rightonly_strugglingandgreatdifficulty <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_strugglingandgreatdifficulty)
# delete_tweet_controls_rrponly_strugglingandgreatdifficulty <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_strugglingandgreatdifficulty)

# robust SEs
robust_delete_tweet_controls_fullsample_strugglingandgreatdifficulty <- summ(delete_tweet_controls_fullsample_strugglingandgreatdifficulty, robust = "HC1")
robust_delete_tweet_controls_leftonly_strugglingandgreatdifficulty <- summ(delete_tweet_controls_leftonly_strugglingandgreatdifficulty, robust = "HC1")
robust_delete_tweet_controls_rightonly_strugglingandgreatdifficulty <- summ(delete_tweet_controls_rightonly_strugglingandgreatdifficulty, robust = "HC1")
# robust_delete_tweet_controls_rrponly_strugglingandgreatdifficulty <- summ(delete_tweet_controls_rrponly_strugglingandgreatdifficulty, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_strugglingandgreatdifficulty_df <- broom::tidy(robust_delete_tweet_controls_fullsample_strugglingandgreatdifficulty) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_strugglingandgreatdifficulty_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_delete_tweet_controls_leftonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_strugglingandgreatdifficulty_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_strugglingandgreatdifficulty_df <- broom::tidy(robust_delete_tweet_controls_rightonly_strugglingandgreatdifficulty) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_strugglingandgreatdifficulty_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_strugglingandgreatdifficulty_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_strugglingandgreatdifficulty_df <- broom::tidy(robust_delete_tweet_controls_rrponly_strugglingandgreatdifficulty) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_strugglingandgreatdifficulty_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_strugglingandgreatdifficulty_df)[7] <- "term"

# final joining of all the models
joined_models_controls_strugglingandgreatdifficulty <- rbind(
  robust_sign_petition_self_controls_fullsample_strugglingandgreatdifficulty_df,
  robust_sign_petition_self_controls_leftonly_strugglingandgreatdifficulty_df,
  robust_sign_petition_self_controls_rightonly_strugglingandgreatdifficulty_df,
  # robust_sign_petition_self_controls_rrponly_strugglingandgreatdifficulty_df,
  robust_sensitive_item_controls_fullsample_strugglingandgreatdifficulty_df,
  robust_sensitive_item_controls_leftonly_strugglingandgreatdifficulty_df,
  robust_sensitive_item_controls_rightonly_strugglingandgreatdifficulty_df,
  # robust_sensitive_item_controls_rrponly_strugglingandgreatdifficulty_df,
  robust_petition_appropriate_self_controls_fullsample_strugglingandgreatdifficulty_df,
  robust_petition_appropriate_self_controls_leftonly_strugglingandgreatdifficulty_df,
  robust_petition_appropriate_self_controls_rightonly_strugglingandgreatdifficulty_df,
  # robust_petition_appropriate_self_controls_rrponly_strugglingandgreatdifficulty_df,
  robust_sign_petition_others_controls_fullsample_strugglingandgreatdifficulty_df,
  robust_sign_petition_others_controls_leftonly_strugglingandgreatdifficulty_df,
  robust_sign_petition_others_controls_rightonly_strugglingandgreatdifficulty_df,
  # robust_sign_petition_others_controls_rrponly_strugglingandgreatdifficulty_df,
  robust_petition_appropriate_others_controls_fullsample_strugglingandgreatdifficulty_df,
  robust_petition_appropriate_others_controls_leftonly_strugglingandgreatdifficulty_df,
  robust_petition_appropriate_others_controls_rightonly_strugglingandgreatdifficulty_df,
  # robust_petition_appropriate_others_controls_rrponly_strugglingandgreatdifficulty_df,
  robust_delete_tweet_controls_fullsample_strugglingandgreatdifficulty_df,
  robust_delete_tweet_controls_leftonly_strugglingandgreatdifficulty_df,
  robust_delete_tweet_controls_rightonly_strugglingandgreatdifficulty_df
  # robust_delete_tweet_controls_rrponly_strugglingandgreatdifficulty_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_strugglingandgreatdifficulty$sample <- factor(joined_models_controls_strugglingandgreatdifficulty$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e8 <- dwplot(joined_models_controls_strugglingandgreatdifficulty,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Struggling and Great Difficulty Only: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e8.png", plot = fig_e8,
  width = 15, height = 10
)

# cleaning - Make Ends Meet

# subset analysis data
analysis_data_makeendsmeet <- analysis_data %>%
  filter(household_income == "Make ends meet")

# mainstream only
mainstream_only_makeendsmeet <- analysis_data_makeendsmeet %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_makeendsmeet <- analysis_data_makeendsmeet %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_makeendsmeet <- analysis_data_makeendsmeet %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_makeendsmeet <- analysis_data_makeendsmeet %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_makeendsmeet[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_makeendsmeet[, c(18, 19, 20, 21, 22, 23)])
left_only_makeendsmeet[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_makeendsmeet[, c(18, 19, 20, 21, 22, 23)])
right_only_makeendsmeet[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_makeendsmeet[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_makeendsmeet[,c(18,19,20,21,22,23)]<-scale(rrp_only_makeendsmeet[,c(18,19,20,21,22,23)])



# Sensitive Item - Make Ends Meet

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_makeendsmeet <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_makeendsmeet)
sensitive_item_controls_leftonly_makeendsmeet <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_makeendsmeet)
sensitive_item_controls_rightonly_makeendsmeet <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_makeendsmeet)
# sensitive_item_controls_rrponly_makeendsmeet <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_makeendsmeet)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_makeendsmeet <- summ(sensitive_item_controls_fullsample_makeendsmeet, robust = "HC1")
robust_sensitive_item_controls_leftonly_makeendsmeet <- summ(sensitive_item_controls_leftonly_makeendsmeet, robust = "HC1")
robust_sensitive_item_controls_rightonly_makeendsmeet <- summ(sensitive_item_controls_rightonly_makeendsmeet, robust = "HC1")
# robust_sensitive_item_controls_rrponly_makeendsmeet <- summ(sensitive_item_controls_rrponly_makeendsmeet, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_makeendsmeet_df <- broom::tidy(robust_sensitive_item_controls_fullsample_makeendsmeet) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_makeendsmeet_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_makeendsmeet_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_makeendsmeet_df <- broom::tidy(robust_sensitive_item_controls_leftonly_makeendsmeet) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_makeendsmeet_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_makeendsmeet_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_makeendsmeet_df <- broom::tidy(robust_sensitive_item_controls_rightonly_makeendsmeet) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_makeendsmeet_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_makeendsmeet_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_makeendsmeet_df <- broom::tidy(robust_sensitive_item_controls_rrponly_makeendsmeet) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_makeendsmeet_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_makeendsmeet_df)[7] <- "term"


# Willingness to Sign Petition - Make Ends Meet


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_makeendsmeet <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_makeendsmeet)
sign_petition_self_controls_leftonly_makeendsmeet <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_makeendsmeet)
sign_petition_self_controls_rightonly_makeendsmeet <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_makeendsmeet)
# sign_petition_self_controls_rrponly_makeendsmeet <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_makeendsmeet)

# robust SEs
robust_sign_petition_self_controls_fullsample_makeendsmeet <- summ(sign_petition_self_controls_fullsample_makeendsmeet, robust = "HC1")
robust_sign_petition_self_controls_leftonly_makeendsmeet <- summ(sign_petition_self_controls_leftonly_makeendsmeet, robust = "HC1")
robust_sign_petition_self_controls_rightonly_makeendsmeet <- summ(sign_petition_self_controls_rightonly_makeendsmeet, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_makeendsmeet <- summ(sign_petition_self_controls_rrponly_makeendsmeet, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_makeendsmeet_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_makeendsmeet) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_makeendsmeet_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_makeendsmeet_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_makeendsmeet_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_makeendsmeet) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_makeendsmeet_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_makeendsmeet_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_makeendsmeet_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_makeendsmeet) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_makeendsmeet_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_makeendsmeet_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_makeendsmeet_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_makeendsmeet) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_makeendsmeet_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_makeendsmeet_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - Make Ends Meet

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_makeendsmeet <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_makeendsmeet)
petition_appropriate_self_controls_leftonly_makeendsmeet <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_makeendsmeet)
petition_appropriate_self_controls_rightonly_makeendsmeet <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_makeendsmeet)
# petition_appropriate_self_controls_rrponly_makeendsmeet <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_makeendsmeet)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_makeendsmeet <- summ(petition_appropriate_self_controls_fullsample_makeendsmeet, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_makeendsmeet <- summ(petition_appropriate_self_controls_leftonly_makeendsmeet, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_makeendsmeet <- summ(petition_appropriate_self_controls_rightonly_makeendsmeet, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_makeendsmeet <- summ(petition_appropriate_self_controls_rrponly_makeendsmeet, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_makeendsmeet) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_makeendsmeet_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_makeendsmeet_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_makeendsmeet) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_makeendsmeet_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_makeendsmeet_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_makeendsmeet) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_makeendsmeet_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_makeendsmeet_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_makeendsmeet) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_makeendsmeet_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_makeendsmeet_df)[7] <- "term"



# Empirical Expectations - Make Ends Meet

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_makeendsmeet <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_makeendsmeet)
sign_petition_others_controls_leftonly_makeendsmeet <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_makeendsmeet)
sign_petition_others_controls_rightonly_makeendsmeet <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_makeendsmeet)
# sign_petition_others_controls_rrponly_makeendsmeet <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_makeendsmeet)

# robust SEs
robust_sign_petition_others_controls_fullsample_makeendsmeet <- summ(sign_petition_others_controls_fullsample_makeendsmeet, robust = "HC1")
robust_sign_petition_others_controls_leftonly_makeendsmeet <- summ(sign_petition_others_controls_leftonly_makeendsmeet, robust = "HC1")
robust_sign_petition_others_controls_rightonly_makeendsmeet <- summ(sign_petition_others_controls_rightonly_makeendsmeet, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_makeendsmeet <- summ(sign_petition_others_controls_rrponly_makeendsmeet, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_makeendsmeet_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_makeendsmeet) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_makeendsmeet_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_makeendsmeet_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_makeendsmeet_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_makeendsmeet) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_makeendsmeet_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_makeendsmeet_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_makeendsmeet_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_makeendsmeet) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_makeendsmeet_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_makeendsmeet_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_makeendsmeet_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_makeendsmeet) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_makeendsmeet_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_makeendsmeet_df)[7] <- "term"



# Normative Expectations - Make Ends Meet

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_makeendsmeet <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_makeendsmeet)
petition_appropriate_others_controls_leftonly_makeendsmeet <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_makeendsmeet)
petition_appropriate_others_controls_rightonly_makeendsmeet <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_makeendsmeet)
# petition_appropriate_others_controls_rrponly_makeendsmeet <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_makeendsmeet)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_makeendsmeet <- summ(petition_appropriate_others_controls_fullsample_makeendsmeet, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_makeendsmeet <- summ(petition_appropriate_others_controls_leftonly_makeendsmeet, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_makeendsmeet <- summ(petition_appropriate_others_controls_rightonly_makeendsmeet, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_makeendsmeet <- summ(petition_appropriate_others_controls_rrponly_makeendsmeet, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_makeendsmeet) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_makeendsmeet_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_makeendsmeet_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_makeendsmeet) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_makeendsmeet_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_makeendsmeet_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_makeendsmeet) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_makeendsmeet_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_makeendsmeet_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_makeendsmeet_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_makeendsmeet) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_makeendsmeet_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_makeendsmeet_df)[7] <- "term"



# Sanctioning - Make Ends Meet

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_makeendsmeet <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_makeendsmeet)
delete_tweet_controls_leftonly_makeendsmeet <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_makeendsmeet)
delete_tweet_controls_rightonly_makeendsmeet <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_makeendsmeet)
# delete_tweet_controls_rrponly_makeendsmeet <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_makeendsmeet)

# robust SEs
robust_delete_tweet_controls_fullsample_makeendsmeet <- summ(delete_tweet_controls_fullsample_makeendsmeet, robust = "HC1")
robust_delete_tweet_controls_leftonly_makeendsmeet <- summ(delete_tweet_controls_leftonly_makeendsmeet, robust = "HC1")
robust_delete_tweet_controls_rightonly_makeendsmeet <- summ(delete_tweet_controls_rightonly_makeendsmeet, robust = "HC1")
# robust_delete_tweet_controls_rrponly_makeendsmeet <- summ(delete_tweet_controls_rrponly_makeendsmeet, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_makeendsmeet_df <- broom::tidy(robust_delete_tweet_controls_fullsample_makeendsmeet) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_makeendsmeet_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_makeendsmeet_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_makeendsmeet_df <- broom::tidy(robust_delete_tweet_controls_leftonly_makeendsmeet) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_makeendsmeet_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_makeendsmeet_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_makeendsmeet_df <- broom::tidy(robust_delete_tweet_controls_rightonly_makeendsmeet) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_makeendsmeet_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_makeendsmeet_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_makeendsmeet_df <- broom::tidy(robust_delete_tweet_controls_rrponly_makeendsmeet) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_makeendsmeet_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_makeendsmeet_df)[7] <- "term"

# final joining of all the models
joined_models_controls_makeendsmeet <- rbind(
  robust_sign_petition_self_controls_fullsample_makeendsmeet_df,
  robust_sign_petition_self_controls_leftonly_makeendsmeet_df,
  robust_sign_petition_self_controls_rightonly_makeendsmeet_df,
  # robust_sign_petition_self_controls_rrponly_makeendsmeet_df,
  robust_sensitive_item_controls_fullsample_makeendsmeet_df,
  robust_sensitive_item_controls_leftonly_makeendsmeet_df,
  robust_sensitive_item_controls_rightonly_makeendsmeet_df,
  # robust_sensitive_item_controls_rrponly_makeendsmeet_df,
  robust_petition_appropriate_self_controls_fullsample_makeendsmeet_df,
  robust_petition_appropriate_self_controls_leftonly_makeendsmeet_df,
  robust_petition_appropriate_self_controls_rightonly_makeendsmeet_df,
  # robust_petition_appropriate_self_controls_rrponly_makeendsmeet_df,
  robust_sign_petition_others_controls_fullsample_makeendsmeet_df,
  robust_sign_petition_others_controls_leftonly_makeendsmeet_df,
  robust_sign_petition_others_controls_rightonly_makeendsmeet_df,
  # robust_sign_petition_others_controls_rrponly_makeendsmeet_df,
  robust_petition_appropriate_others_controls_fullsample_makeendsmeet_df,
  robust_petition_appropriate_others_controls_leftonly_makeendsmeet_df,
  robust_petition_appropriate_others_controls_rightonly_makeendsmeet_df,
  # robust_petition_appropriate_others_controls_rrponly_makeendsmeet_df,
  robust_delete_tweet_controls_fullsample_makeendsmeet_df,
  robust_delete_tweet_controls_leftonly_makeendsmeet_df,
  robust_delete_tweet_controls_rightonly_makeendsmeet_df
  # robust_delete_tweet_controls_rrponly_makeendsmeet_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_makeendsmeet$sample <- factor(joined_models_controls_makeendsmeet$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e7 <- dwplot(joined_models_controls_makeendsmeet,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Make Ends Meet Only: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))


ggsave(
  filename = "plots/fig_e7.png", plot = fig_e7,
  width = 15, height = 10
)

# cleaning - Live Comfortably

# subset analysis data
analysis_data_livecomfortably <- analysis_data %>%
  filter(household_income == "Live comfortable")

# mainstream only
mainstream_only_livecomfortably <- analysis_data_livecomfortably %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_livecomfortably <- analysis_data_livecomfortably %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_livecomfortably <- analysis_data_livecomfortably %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_livecomfortably <- analysis_data_livecomfortably %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_livecomfortably[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_livecomfortably[, c(18, 19, 20, 21, 22, 23)])
left_only_livecomfortably[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_livecomfortably[, c(18, 19, 20, 21, 22, 23)])
right_only_livecomfortably[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_livecomfortably[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_livecomfortably[,c(18,19,20,21,22,23)]<-scale(rrp_only_livecomfortably[,c(18,19,20,21,22,23)])



# Sensitive Item - Live Comfortably

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_livecomfortably <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_livecomfortably)
sensitive_item_controls_leftonly_livecomfortably <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_livecomfortably)
sensitive_item_controls_rightonly_livecomfortably <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_livecomfortably)
# sensitive_item_controls_rrponly_livecomfortably <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_livecomfortably)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_livecomfortably <- summ(sensitive_item_controls_fullsample_livecomfortably, robust = "HC1")
robust_sensitive_item_controls_leftonly_livecomfortably <- summ(sensitive_item_controls_leftonly_livecomfortably, robust = "HC1")
robust_sensitive_item_controls_rightonly_livecomfortably <- summ(sensitive_item_controls_rightonly_livecomfortably, robust = "HC1")
# robust_sensitive_item_controls_rrponly_livecomfortably <- summ(sensitive_item_controls_rrponly_livecomfortably, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_livecomfortably_df <- broom::tidy(robust_sensitive_item_controls_fullsample_livecomfortably) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_livecomfortably_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_livecomfortably_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_livecomfortably_df <- broom::tidy(robust_sensitive_item_controls_leftonly_livecomfortably) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_livecomfortably_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_livecomfortably_df)[7] <- "term"


robust_sensitive_item_controls_rightonly_livecomfortably_df <- broom::tidy(robust_sensitive_item_controls_rightonly_livecomfortably) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_livecomfortably_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_livecomfortably_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_livecomfortably_df <- broom::tidy(robust_sensitive_item_controls_rrponly_livecomfortably) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_livecomfortably_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_livecomfortably_df)[7] <- "term"


# Willingness to Sign Petition - Live Comfortably


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_livecomfortably <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_livecomfortably)
sign_petition_self_controls_leftonly_livecomfortably <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_livecomfortably)
sign_petition_self_controls_rightonly_livecomfortably <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_livecomfortably)
# sign_petition_self_controls_rrponly_livecomfortably <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_livecomfortably)

# robust SEs
robust_sign_petition_self_controls_fullsample_livecomfortably <- summ(sign_petition_self_controls_fullsample_livecomfortably, robust = "HC1")
robust_sign_petition_self_controls_leftonly_livecomfortably <- summ(sign_petition_self_controls_leftonly_livecomfortably, robust = "HC1")
robust_sign_petition_self_controls_rightonly_livecomfortably <- summ(sign_petition_self_controls_rightonly_livecomfortably, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_livecomfortably <- summ(sign_petition_self_controls_rrponly_livecomfortably, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_livecomfortably_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_livecomfortably) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_livecomfortably_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_livecomfortably_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_livecomfortably_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_livecomfortably) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_livecomfortably_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_livecomfortably_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_livecomfortably_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_livecomfortably) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_livecomfortably_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_livecomfortably_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_livecomfortably_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_livecomfortably) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_livecomfortably_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_livecomfortably_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - Live Comfortably

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_livecomfortably <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_livecomfortably)
petition_appropriate_self_controls_leftonly_livecomfortably <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_livecomfortably)
petition_appropriate_self_controls_rightonly_livecomfortably <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_livecomfortably)
# petition_appropriate_self_controls_rrponly_livecomfortably <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_livecomfortably)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_livecomfortably <- summ(petition_appropriate_self_controls_fullsample_livecomfortably, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_livecomfortably <- summ(petition_appropriate_self_controls_leftonly_livecomfortably, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_livecomfortably <- summ(petition_appropriate_self_controls_rightonly_livecomfortably, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_livecomfortably <- summ(petition_appropriate_self_controls_rrponly_livecomfortably, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_livecomfortably_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_livecomfortably) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_livecomfortably_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_livecomfortably_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_livecomfortably_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_livecomfortably) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_livecomfortably_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_livecomfortably_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_livecomfortably_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_livecomfortably) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_livecomfortably_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_livecomfortably_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_livecomfortably_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_livecomfortably) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_livecomfortably_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_livecomfortably_df)[7] <- "term"



# Empirical Expectations - Live Comfortably

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_livecomfortably <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_livecomfortably)
sign_petition_others_controls_leftonly_livecomfortably <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_livecomfortably)
sign_petition_others_controls_rightonly_livecomfortably <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_livecomfortably)
# sign_petition_others_controls_rrponly_livecomfortably <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_livecomfortably)

# robust SEs
robust_sign_petition_others_controls_fullsample_livecomfortably <- summ(sign_petition_others_controls_fullsample_livecomfortably, robust = "HC1")
robust_sign_petition_others_controls_leftonly_livecomfortably <- summ(sign_petition_others_controls_leftonly_livecomfortably, robust = "HC1")
robust_sign_petition_others_controls_rightonly_livecomfortably <- summ(sign_petition_others_controls_rightonly_livecomfortably, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_livecomfortably <- summ(sign_petition_others_controls_rrponly_livecomfortably, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_livecomfortably_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_livecomfortably) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_livecomfortably_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_livecomfortably_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_livecomfortably_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_livecomfortably) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_livecomfortably_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_livecomfortably_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_livecomfortably_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_livecomfortably) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_livecomfortably_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_livecomfortably_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_livecomfortably_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_livecomfortably) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_livecomfortably_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_livecomfortably_df)[7] <- "term"



# Normative Expectations - Live Comfortably

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_livecomfortably <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_livecomfortably)
petition_appropriate_others_controls_leftonly_livecomfortably <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_livecomfortably)
petition_appropriate_others_controls_rightonly_livecomfortably <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_livecomfortably)
# petition_appropriate_others_controls_rrponly_livecomfortably <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_livecomfortably)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_livecomfortably <- summ(petition_appropriate_others_controls_fullsample_livecomfortably, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_livecomfortably <- summ(petition_appropriate_others_controls_leftonly_livecomfortably, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_livecomfortably <- summ(petition_appropriate_others_controls_rightonly_livecomfortably, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_livecomfortably <- summ(petition_appropriate_others_controls_rrponly_livecomfortably, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_livecomfortably_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_livecomfortably) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_livecomfortably_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_livecomfortably_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_livecomfortably_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_livecomfortably) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_livecomfortably_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_livecomfortably_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_livecomfortably_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_livecomfortably) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_livecomfortably_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_livecomfortably_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_livecomfortably_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_livecomfortably) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_livecomfortably_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_livecomfortably_df)[7] <- "term"



# Sanctioning - Live Comfortably

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_livecomfortably <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = analysis_data_livecomfortably)
delete_tweet_controls_leftonly_livecomfortably <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = left_only_livecomfortably)
delete_tweet_controls_rightonly_livecomfortably <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + education + left_right, data = right_only_livecomfortably)
# delete_tweet_controls_rrponly_livecomfortably <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + education + left_right, data = rrp_only_livecomfortably)

# robust SEs
robust_delete_tweet_controls_fullsample_livecomfortably <- summ(delete_tweet_controls_fullsample_livecomfortably, robust = "HC1")
robust_delete_tweet_controls_leftonly_livecomfortably <- summ(delete_tweet_controls_leftonly_livecomfortably, robust = "HC1")
robust_delete_tweet_controls_rightonly_livecomfortably <- summ(delete_tweet_controls_rightonly_livecomfortably, robust = "HC1")
# robust_delete_tweet_controls_rrponly_livecomfortably <- summ(delete_tweet_controls_rrponly_livecomfortably, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_livecomfortably_df <- broom::tidy(robust_delete_tweet_controls_fullsample_livecomfortably) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_livecomfortably_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_livecomfortably_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_livecomfortably_df <- broom::tidy(robust_delete_tweet_controls_leftonly_livecomfortably) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_livecomfortably_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_livecomfortably_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_livecomfortably_df <- broom::tidy(robust_delete_tweet_controls_rightonly_livecomfortably) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_livecomfortably_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_livecomfortably_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_livecomfortably_df <- broom::tidy(robust_delete_tweet_controls_rrponly_livecomfortably) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_livecomfortably_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_livecomfortably_df)[7] <- "term"

# final joining of all the models
joined_models_controls_livecomfortably <- rbind(
  robust_sign_petition_self_controls_fullsample_livecomfortably_df,
  robust_sign_petition_self_controls_leftonly_livecomfortably_df,
  robust_sign_petition_self_controls_rightonly_livecomfortably_df,
  # robust_sign_petition_self_controls_rrponly_livecomfortably_df,
  robust_sensitive_item_controls_fullsample_livecomfortably_df,
  robust_sensitive_item_controls_leftonly_livecomfortably_df,
  robust_sensitive_item_controls_rightonly_livecomfortably_df,
  # robust_sensitive_item_controls_rrponly_livecomfortably_df,
  robust_petition_appropriate_self_controls_fullsample_livecomfortably_df,
  robust_petition_appropriate_self_controls_leftonly_livecomfortably_df,
  robust_petition_appropriate_self_controls_rightonly_livecomfortably_df,
  # robust_petition_appropriate_self_controls_rrponly_livecomfortably_df,
  robust_sign_petition_others_controls_fullsample_livecomfortably_df,
  robust_sign_petition_others_controls_leftonly_livecomfortably_df,
  robust_sign_petition_others_controls_rightonly_livecomfortably_df,
  # robust_sign_petition_others_controls_rrponly_livecomfortably_df,
  robust_petition_appropriate_others_controls_fullsample_livecomfortably_df,
  robust_petition_appropriate_others_controls_leftonly_livecomfortably_df,
  robust_petition_appropriate_others_controls_rightonly_livecomfortably_df,
  # robust_petition_appropriate_others_controls_rrponly_livecomfortably_df,
  robust_delete_tweet_controls_fullsample_livecomfortably_df,
  robust_delete_tweet_controls_leftonly_livecomfortably_df,
  robust_delete_tweet_controls_rightonly_livecomfortably_df
  # robust_delete_tweet_controls_rrponly_livecomfortably_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_livecomfortably$sample <- factor(joined_models_controls_livecomfortably$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e6 <- dwplot(joined_models_controls_livecomfortably,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Live Comfortably Only: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e6.png", plot = fig_e6,
  width = 15, height = 10
)
